#include <stdio.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>

int main()
{
    pid_t pid;
    if((pid=fork())==-1)
        perror("fork"),exit(1);

    if(pid==0)
    {
        sleep(5);
        exit(10);
    }
    else 
    {
        int st;
        int ret=wait(&st);

        if(ret>0 && (st & 0x7f)==0  )
        {
            // 正常退出
            printf("child exit code:%d\n",(st>>8)&0xff);
        }
        else if(ret>0)
        {
            printf("sign code: %d\n",st&0x7f);
        }
    }
}
